﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HardToolApp.Model
{
    public class PwmModel: ObservableObject
    {
        public class PWM : Peripheral
        {
            static string[] PWMPin = { "PB6", "PA0" };
            public byte ID { get; set; }
            [ObservableProperty]
            UInt32 freq = 2000;
            public UInt32 Freq { get => freq; set => SetProperty(ref freq,value); }
            [ObservableProperty]
            Double duty = 50.00;
            public Double Duty { get => duty; set => SetProperty(ref duty, value); }
            bool? needOpen = false;
            public bool? NeedOpen { get => needOpen;set=>SetProperty(ref needOpen, value); }
            public PWM() : base(CommCmd.COMM_PWM)
            {

            }
            public override string ToString()
            {
                switch(subCmd)
                {
                    case 1:
                        return "设置" + PWMPin[ID] + "参数->频率" + Freq + "HZ,占空比" + Duty + "%\n";
                    case 2:
                        return "打开" + PWMPin[ID] + "PWM输出\n";
                    case 3:
                        return "关闭" + PWMPin[ID] + "PWM输出\n";
                    default:
                        return "未知命令";
                }
            }
        }
        public PwmModel()
        {
            PWMs[0] = new PWM();
            PWMs[1] = new PWM();
            PWMs[0].ID = 0;
            PWMs[1].ID = 1;
        }
        public PWM[] PWMs { get; set; } = new PWM[2];
    }
}
